﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace visu.Controllers
{
    public class MessageController : Controller
    {
        //
        // GET: /Message/

        #region=================================安全库存预警==================================================
        public ActionResult MaterialSafetyStockAlert()
        {
            return View();
        }
        public ActionResult MaterialSafetyStockAlertDetail(int page, int rows, vmaterialsafetystock materialsafetystock, string SearchContains, string sort, string order)
        {
            sort = string.IsNullOrEmpty(sort) ? "ID" : sort;
            order = string.IsNullOrEmpty(order) ? "asc" : order;

            SearchCondition condition = new SearchCondition() { Field = "COMPANY_ID", Operator = "=", Value = OperateContext.userInfo.COMPANY_ID.ToString() };
            List<SearchCondition> listSearch = new List<SearchCondition>();
            listSearch.Add(condition);

            Expression<Func<vmaterialsafetystock, bool>> exp = SearchExpression.GetSearchExpression<vmaterialsafetystock>(materialsafetystock, listSearch, SearchContains, "M_SPECIFICATION", "M_CODE", "PRODUCT_NO", "M_TYPE");

            var list = BLLSession.Current.vmaterialsafetystockBLL.GetPagedList(page, rows, exp, sort, order);
            int count = DALSession.Current.vmaterialsafetystockDAL.GetCount(exp);
            LayuiDataPager dataPager = new LayuiDataPager() { code = 0, count = count, data = list, msg = "", total = count, rows = list };

            return Json(dataPager, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region=================================呆滞料预警==================================================
        public ActionResult MaterialIdleAlert()
        {
            return View();
        }
        public ActionResult MaterialIdleAlertDetail(int page, int rows, vinventoryontime vinventoryontime, string SearchContains, string sort, string order)
        {
            sort = string.IsNullOrEmpty(sort) ? "ID" : sort;
            order = string.IsNullOrEmpty(order) ? "asc" : order;

            SearchCondition condition = new SearchCondition() { Field = "COMPANY_ID", Operator = "=", Value = OperateContext.userInfo.COMPANY_ID.ToString() };
            SearchCondition condition1 = new SearchCondition() { Field = "IS_IDLE", Operator = "=", Value = "1" };
            List<SearchCondition> listSearch = new List<SearchCondition>();
            listSearch.Add(condition);
            listSearch.Add(condition1);
            Expression<Func<vinventoryontime, bool>> exp = SearchExpression.GetSearchExpression<vinventoryontime>(vinventoryontime, listSearch, SearchContains, "M_SPECIFICATION", "M_CODE", "PRODUCT_NO", "M_TYPE");

            var list = BLLSession.Current.vinventoryontimeBLL.GetPagedList(page, rows, exp, sort, order);
            int count = DALSession.Current.vinventoryontimeDAL.GetCount(exp);
            LayuiDataPager dataPager = new LayuiDataPager() { code = 0, count = count, data = list, msg = "", total = count, rows = list };

            return Json(dataPager, JsonRequestBehavior.AllowGet);
        }
        #endregion
        #region=================================借出物料预警==================================================
        public ActionResult MaterialNoReturnAlert()
        {
            return View();
        }
        public ActionResult MaterialNoReturnAlertDetail(int page, int rows, vmaterialnoreturn vmaterialnoreturn, string SearchContains, string sort, string order)
        {
            sort = string.IsNullOrEmpty(sort) ? "ID" : sort;
            order = string.IsNullOrEmpty(order) ? "asc" : order;

            SearchCondition condition = new SearchCondition() { Field = "COMPANY_ID", Operator = "=", Value = OperateContext.userInfo.COMPANY_ID.ToString() };
            List<SearchCondition> listSearch = new List<SearchCondition>();
            listSearch.Add(condition);

            Expression<Func<vmaterialnoreturn, bool>> exp = SearchExpression.GetSearchExpression<vmaterialnoreturn>(vmaterialnoreturn, listSearch, SearchContains, "M_SPECIFICATION", "M_CODE", "PRODUCT_NO", "M_TYPE");

            var list = BLLSession.Current.vmaterialnoreturnBLL.GetPagedList(page, rows, exp, sort, order);
            int count = DALSession.Current.vmaterialnoreturnDAL.GetCount(exp);
            LayuiDataPager dataPager = new LayuiDataPager() { code = 0, count = count, data = list, msg = "", total = count, rows = list };

            return Json(dataPager, JsonRequestBehavior.AllowGet);
        }
        #endregion
        #region=================================消息列表==================================================
        public ActionResult MessageListInfo()
        {
            return View();
        }
        public ActionResult MessageListInfoDetail(int page, int rows, vmessagelist messagelist, string SearchContains, string sort, string order)
        {
            sort = string.IsNullOrEmpty(sort) ? "MESSAGE_ID" : sort;
            order = string.IsNullOrEmpty(order) ? "asc" : order;

            SearchCondition condition = new SearchCondition() { Field = "COMPANY_ID", Operator = "=", Value = OperateContext.userInfo.COMPANY_ID.ToString() };
            List<SearchCondition> listSearch = new List<SearchCondition>();
            listSearch.Add(condition);

            Expression<Func<vmessagelist, bool>> exp = SearchExpression.GetSearchExpression<vmessagelist>(messagelist, listSearch, SearchContains, "MESSAGE_TYPE", "MESSAGE_TEXT", "NAME");

            var list = BLLSession.Current.vmessagelistBLL.GetPagedList(page, rows, exp, sort, order);
            int count = DALSession.Current.vmessagelistDAL.GetCount(exp);
            LayuiDataPager dataPager = new LayuiDataPager() { code = 0, count = count, data = list, msg = "", total = count, rows = list };

            return Json(dataPager, JsonRequestBehavior.AllowGet);
        }
        #endregion


    }
}
